$(function() {
	
	//初始化====================================
	$("#dataGird").flexigrid({
		url: "/budgetcalc/summary/selectForPage.json",
		colModel : [
		    {display: "ID", name : "id", width : 150, sortable : true,hide: true},
			{display: "项目名称", name : "name", width : 400, sortable : true, align: "center"},
			{display: "总合同", name : "contractValue", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "已完成(%)", name : "completedRate", width : 90, sortable : true, align: "center", process:formatPercent},
			{display: "预算期核算期完成额", name : "budgetcalcCplValue", width : 110, sortable : true, align: "center",process:formatCost},
			{display: "[项目费用]测量", name : "geosurveyCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "地勘", name : "surveyCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "其它", name : "otherCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "内业", name : "designCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "项目费用合计(元)", name : "outsideCount", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "[公司成本]经营部", name : "companycostBusinessdeptCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "总工办", name : "companycostChiefengCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "领导", name : "companycostLeaderCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "招待费", name : "companycostEntertainCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "会务等其它", name : "companycostConferenceCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "劳务费", name : "companycostLaborCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "招投标费", name : "companycostBiddingCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "出版装订", name : "companycostPublishCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "产值管理", name : "companycostOutputvalueCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "工资/奖金", name : "companycostWageCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "公司设备费", name : "companycostEquCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "领导招待费", name : "companycostLeaderentCost", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "公司成本合计(元)", name : "companycostCount", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "分院成本", name : "branchSummary", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "总计(元)", name : "totalCount", width : 90, sortable : true, align: "center",process:formatCost},
			{display: "利润(元)", name : "profitCount", width : 90, sortable : true, align: "center",process:formatCost}
		]
    });
	
	
	//事件监控====================================
	//重置表单
	$("#clearButton").bind("click",function(){
		MZ.reset("searchForm");
	});
	
	//查询数据
	$("#searchButton").bind("click",function(){
		MZ.searchGird("searchForm","dataGird");
	});
	
	//EXPORT数据
	$("#exportA").bind("click",function(){
		//MZ.showMsg("未完善的功能，请等待...");
		var name = $("#projectName").val();
		var st = $("#startTime").val();
		var et = $("#endTime").val();
		if(name == ""){
			name = "-1";
		}
		if(st == ""){
			st = "-1";
		}
		if(et == ""){
			et = "-1";
		}
		window.location.href = "/budgetcalc/summary/exportSummary/"+ encodeURI(encodeURI(name))+"/"+st+"/"+et;
	});
});
function formatPercent(tdDiv, pid){
	var val = $(tdDiv).text();
	if(val != ""){
		val += "%";
	}
	return val;
}
function formatCost(tdDiv, pid){
	var cost = $(tdDiv).text();
	if(cost == "0"){
		return "";
	}
	return MZ.toDecimal(cost/MZ.CURRENCY_PRECISION , MZ.CURRENCY_ROUND);
}